<template>
  <div>
    <van-form @submit="onSubmit">
      <van-field
        v-model="username"
        name="username"
        label="用户名"
        placeholder="用户名"
        :rules="[{ required: true, message: '请填写用户名' }]"
      />
      <van-field
        v-model="password"
        type="password"
        name="password"
        label="密码"
        placeholder="密码"
        :rules="[{ required: true, message: '请填写密码' }]"
      />
      <van-radio-group v-model="radio" direction="horizontal">
        <van-radio name="1">管理员登录</van-radio>
        <van-radio name="2">商户登录</van-radio>
      </van-radio-group>
      <div style="margin: 16px;">
        <van-button round block type="info" native-type="submit"
          >提交</van-button
        >
      </div>
    </van-form>
  </div>
</template>

<script>
import Vue from 'vue';
import { Toast } from 'vant';
Vue.use(Toast);
export default {
  data() {
    return {
      username: "",
      password: "",
      radio: '1',
    };
  },
  methods: {
    onSubmit(values) {
      if(this.radio==1){
        // 管理员登录接口
      }else{
          this.$store.dispatch('postUserLogin',values).then(res=>{
            if(res.code==200){
              Toast.success('登录成功');
              this.$router.push('/merchant')
            }else{
              Toast.fail('账号或密码错误');
            }
          })
      }
      

    },
  },
};
</script>

<style scoped></style>
